<template>
  <div class="lang">
    <el-dropdown @command="commandEvent">
      <span class="svgIcon">
        <svg-icon icon-class="language" />
      </span>
      <template #dropdown>
        <div>
          <el-dropdown-menu>
            <el-dropdown-item
              command="zh"
              :disabled="$i18n.locale === 'zh'"
            >中文</el-dropdown-item>
            <el-dropdown-item
              command="en"
              :disabled="$i18n.locale === 'en'"
            >English</el-dropdown-item>
          </el-dropdown-menu>
        </div>
      </template>
    </el-dropdown>
  </div>
</template>

<script>
import Cookie from 'js-cookie'
export default {
  name: 'Lang',
  methods: {
    commandEvent(command) {
      this.$i18n.locale = command
      Cookie.set('lang', command)
      this.$router.go()
    }
  }
}
</script>

<style lang="scss" scoped>
.lang {
  .svgIcon {
    font-size: 24px;
    color: #fff;
  }
}
</style>
